import React, { createRef} from 'react';
import {
    message,
    Form,
    Input,
    Button,
    Select,
    InputNumber,
    Switch,
    DatePicker
} from 'antd';

import { connect } from 'react-redux'
import request, { baseUrl } from '@/utils/request'
import { withNavigate } from '../../../utils/hoc';

class Add extends React.PureComponent {
    state = {
        goods: {
            complete: true
        },

        // 用于存放商品商品文件列表
        fileList: []
    }

    // 添加商品
    submit = async (values) => {
        const { navigate } = this.props;
        const { data } = await request.post('/order/addData', values)
        console.log('data', data)
        if (data.code === 200) {


            message.success('商品添加成功')

            navigate('/manage/order/list')
        }
    }

    UNSAFE_componentWillMount() {
        this.rules = {
            goods_name: [{
                required: true,
                message: '请填写商品名称'
            }]
        }
    }
   
    render() {
        const { rules, submit } = this;
        const { goods, category} = this.state;

        return (
            <Form
                labelCol={{ span: 4 }}
                wrapperCol={{ span: 18 }}
                layout="horizontal"
                initialValues={goods}
                onFinish={submit}
            >
                <Form.Item label="菜品名称" name="dishes_name" rules={rules.goods_name}>
                    <Input />
                </Form.Item>
                <Form.Item label="完成时间" name='complete_time'>
          <DatePicker />
        </Form.Item>
                <Form.Item label="订单总价" name='sales_price'>
                    <InputNumber />
                </Form.Item>
                <Form.Item label="手机号" name='telephone'>
                    <InputNumber />
                </Form.Item>
                <Form.Item label="是否完成" name='complete' valuePropName="checked">
                    <Switch />
                </Form.Item>
                <Form.Item wrapperCol={{ offset: 4 }}>
                    <Button type='primary' htmlType='submit'>添加</Button>
                </Form.Item>
            </Form>
        )
    }
}

const mapStateToProps = function (state) {
    return {
        user: state.userInfo
    }
}
Add = connect(mapStateToProps)(Add)

Add = withNavigate(Add)

export default Add;